/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package matching;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.semanticweb.owl.model.OWLClass;
import org.semanticweb.owl.model.OWLDataProperty;
import org.semanticweb.owl.model.OWLDescription;
import org.semanticweb.owl.model.OWLOntology;


/**
 *
 * @author livia
 */
public class VocabularyMatching {
    
    public OWLOntology source;
    public OWLOntology target;
    public String sourceName;
    public String targetName;
   
    public ArrayList<Matching> matchings;

    public VocabularyMatching(OWLOntology source, OWLOntology target, String sourceName, String targetName) {
        this.source = source;
        this.target = target;
        this.sourceName=sourceName;
        this.targetName = targetName;
        this.matchings = new ArrayList<Matching>();
    }

    public void addMatching(Matching m) throws Exception{
      /*  if(m.isClass()){
            if(!checkedClass(m.getSource().getElement(), source)||
               !checkedClass(m.getTarget().getElement(), target))
                throw new Exception("classes nao encontrdas");
            if(!matchings.contains(m)){
                matchings.add(m);
            }
        } else{
            if(!checkedProperty(m.getSource().getElement(), source)||
               !checkedProperty(m.getTarget().getElement(), target))
                throw new Exception("classes nao encontrdas");
            if(!matchings.contains(m)){
                matchings.add(m);
            }
        }*/
    	//checar propriedades de dados 
    	 matchings.add(m);
    }

    public Collection<Matching> getMatchings(){
        return matchings;
    }

    /**/
    private boolean checkedClass(String cl, OWLOntology onto){
        for (OWLClass cls : onto.getReferencedClasses()){
             if(cl.equals(cls.toString())) return true;
        }
        return false;
    }

    //verifica se o metodo para pegar propriedades eh esse
    private boolean checkedProperty(OWLDataProperty prop, OWLOntology onto){
    	
    	for (OWLDescription cl : prop.getDomains(onto)) {
             
        }
        return false;
    }

    public ArrayList<Matching> getMatching(){
        return matchings;
    }

    public boolean hasMatch(Matching m){
        Matching matching;
        for (Iterator<Matching> it = matchings.iterator(); it.hasNext();) {
            matching = it.next();
            if(m.equals(matching))return true;
        }
        return false;
    }
    
    public void prin() {
		for (Matching m : matchings) {
			System.out.print(sourceName+":"+m.source.getElement()+
					" "+sourceName+":"+m.source.getContext()+
					" "+sourceName+":"+m.source.getRestriction()+"  ");
			System.out.println(targetName+":"+m.target.getElement()+" "
					+targetName+":"+m.target.getContext()+" "
					+targetName+":"+m.target.getRestriction());
		}

	}
}
